package com.elock.entity;

import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import javax.persistence.PrePersist;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import com.elock.base.core.Sequence;
import com.elock.base.core.entity.BaseEntity;

/**
 * Entity - 任务信息
 * 
 * @author 仁德
 */
@Entity
@Table(name = "terminal_task")
@SequenceGenerator(name = "sequenceGenerator", sequenceName = "terminal_task_sequence")
public class TerminalTask extends BaseEntity {

	private static final long serialVersionUID = 1386745660360951034L;

	/** 流水号 */
	private String sn;

	/** 运单号 */
	private String waybillNo;

	/** 任务类别 */
	private SystemDict category;

	/** 提油机构 */
	private SaleOrg fromSaleOrg;

	/** 开锁模式：0 M1自动模式, 1 M2手动模式 */
	private int unlockMode;

	/** 状态：0 未完成, 1 已完成 2 已关闭 */
	private int status;

	/** 备注 */
	private String memo;

	/** 鹤位 */
	private Integer position;

	/** 车牌号 */
	private String plateNum;

	/** 舱位 */
	private Integer berth;

	/** 出发时间 */
	private Date startTime;

	/** 预计到达时间 */
	private Date endTime;

	/** 配送时长 */
	private String duration;

	/** 容量 */
	private BigDecimal volume;

	/** 品名 */
	private String goods;

	/** 数量 */
	private BigDecimal quantity;

	/** 卸油机构 */
	private SaleOrg toSaleOrg;

	/** 任务明细信息 */
	// private List<TerminalTaskItem> terminalTaskItems = new
	// ArrayList<TerminalTaskItem>();

	/**
	 * 获取sn
	 * 
	 * @return sn sn
	 */
	@Column(unique = true, updatable = false)
	public String getSn() {
		return sn;
	}

	/**
	 * 设置sn
	 * 
	 * @param sn
	 *            sn
	 */
	public void setSn(String sn) {
		this.sn = sn;
	}

	/**
	 * 获取waybillNo
	 * 
	 * @return waybillNo waybillNo
	 */
	public String getWaybillNo() {
		return waybillNo;
	}

	/**
	 * 设置waybillNo
	 * 
	 * @param waybillNo
	 *            waybillNo
	 */
	public void setWaybillNo(String waybillNo) {
		this.waybillNo = waybillNo;
	}

	/**
	 * 获取category
	 * 
	 * @return category category
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	public SystemDict getCategory() {
		return category;
	}

	/**
	 * 设置category
	 * 
	 * @param category
	 *            category
	 */
	public void setCategory(SystemDict category) {
		this.category = category;
	}

	/**
	 * 获取fromSaleOrg
	 * 
	 * @return fromSaleOrg fromSaleOrg
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	public SaleOrg getFromSaleOrg() {
		return fromSaleOrg;
	}

	/**
	 * 设置fromSaleOrg
	 * 
	 * @param fromSaleOrg
	 *            fromSaleOrg
	 */
	public void setFromSaleOrg(SaleOrg fromSaleOrg) {
		this.fromSaleOrg = fromSaleOrg;
	}

	/**
	 * 获取unlockMode
	 * 
	 * @return unlockMode unlockMode
	 */
	public int getUnlockMode() {
		return unlockMode;
	}

	/**
	 * 设置unlockMode
	 * 
	 * @param unlockMode
	 *            unlockMode
	 */
	public void setUnlockMode(int unlockMode) {
		this.unlockMode = unlockMode;
	}

	/**
	 * 获取status
	 * 
	 * @return status status
	 */
	public int getStatus() {
		return status;
	}

	/**
	 * 设置status
	 * 
	 * @param status
	 *            status
	 */
	public void setStatus(int status) {
		this.status = status;
	}

	/**
	 * 获取memo
	 * 
	 * @return memo memo
	 */
	public String getMemo() {
		return memo;
	}

	/**
	 * 设置memo
	 * 
	 * @param memo
	 *            memo
	 */
	public void setMemo(String memo) {
		this.memo = memo;
	}

	/**
	 * 获取terminalTaskItems
	 * 
	 * @return terminalTaskItems terminalTaskItems
	 */
	// @OneToMany(mappedBy = "terminalTask", fetch = FetchType.LAZY, cascade =
	// CascadeType.ALL, orphanRemoval = true)
	// public List<TerminalTaskItem> getTerminalTaskItems() {
	// return terminalTaskItems;
	// }

	/**
	 * 设置terminalTaskItems
	 * 
	 * @param terminalTaskItems
	 *            terminalTaskItems
	 */
	// public void setTerminalTaskItems(List<TerminalTaskItem>
	// terminalTaskItems) {
	// this.terminalTaskItems = terminalTaskItems;
	// }

	public Integer getPosition() {
		return position;
	}

	public void setPosition(Integer position) {
		this.position = position;
	}

	public String getPlateNum() {
		return plateNum;
	}

	public void setPlateNum(String plateNum) {
		this.plateNum = plateNum;
	}

	public Integer getBerth() {
		return berth;
	}

	public void setBerth(Integer berth) {
		this.berth = berth;
	}

	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}

	public String getDuration() {
		return duration;
	}

	public void setDuration(String duration) {
		this.duration = duration;
	}

	public BigDecimal getVolume() {
		return volume;
	}

	public void setVolume(BigDecimal volume) {
		this.volume = volume;
	}

	public String getGoods() {
		return goods;
	}

	public void setGoods(String goods) {
		this.goods = goods;
	}

	public BigDecimal getQuantity() {
		return quantity;
	}

	public void setQuantity(BigDecimal quantity) {
		this.quantity = quantity;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	public SaleOrg getToSaleOrg() {
		return toSaleOrg;
	}

	public void setToSaleOrg(SaleOrg toSaleOrg) {
		this.toSaleOrg = toSaleOrg;
	}

	/**
	 * 持久化前处理
	 */
	@PrePersist
	public void prePersist() {
		if (getSn() == null) {
			setSn(Sequence.getInstance().getSequence(null));
		}
	}
}
